import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  server: {
    proxy: {
      //代理配置
      "/hehe": {
        target: "https://m.wzj.com/", //目标域名
        changeOrigin: true,
        configure: (proxy, options) => {
          proxy.on("proxyReq", (proxyReq, req, res) => {
            // 在代理请求中添加自定义 header ，伪装本次请求
            proxyReq.setHeader("Referer", "https://m.wzj.com/mall");
          });
        },
        rewrite: (path) => path.replace(/^\/hehe/, ""),
      },
      "/heihei": {
        target: "https://baidu.com", //目标域名
        changeOrigin: true,
        configure: (proxy, options) => {
          proxy.on("proxyReq", (proxyReq, req, res) => {
            // 在代理请求中添加自定义 header ，伪装本次请求
            proxyReq.setHeader("Referer", "https://baidu.com");
          });
        },
        rewrite: (path) => path.replace(/^\/heihei/, ""),
      },
    },
  },
});
